package com.xxx.blog.service.impl;

import com.github.pagehelper.PageHelper;
import com.xxx.blog.domain.Article;
import com.xxx.blog.mapper.ArticleMapper;
import com.xxx.blog.query.ArticleQuery;
import com.xxx.blog.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ArticleServiceImpl implements IArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<Article> findAll() {
        return articleMapper.findAll();
    }

    @Override
    public Article findOne(Long id) {
        return articleMapper.findOne(id);
    }

    @Override
    public List<Article> queryPage(ArticleQuery articleQuery) {
        PageHelper.startPage(articleQuery.getCurrentPage(), articleQuery.getPageSize());
        return articleMapper.queryPage(articleQuery);
    }

    @Override
    public void addArticle(Article article) {
        articleMapper.addArticle(article);
    }

    @Override
    public void updateArticle(Article article) {
        article.setUpdateTime(new Date());
        articleMapper.updateArticle(article);
    }

    @Override
    public void delete(Long id) {
        articleMapper.delete(id);
    }

    @Override
    public void batchDeletes(Long[] ids) {
        articleMapper.batchDeletes(ids);
    }
}